import axios from 'axios'
import JSONbig from 'json-bigint'
const request = axios.create({
  baseURL:'http://api-toutiao-web.itheima.net',
  transformResponse: [function (data) {
    // 对接收的 data 进行任意转换处理
    try {
      return JSONbig.parse(data)
      // return data;
    } catch (error) {
    return data;
    }
  }],
})
request.interceptors.request.use(config => {
// Do something before request is sent
// if(user)
const user = JSON.parse(window.localStorage.getItem('user'))
// console.log(user);
if(user){
  config.headers.Authorization= `Bearer ${user.token}`
}
return config;
},error => {
// Do something with request error
return Promise.reject(error);
});
export default request
